#include <avr/io.h>
#include <util/delay.h>


/*Η παρακάτω δήλωση ελέγχει αν στον compiler έχουμε βάλει την παράμετρο F_CPU.
  Αν όχι, την περνά. */

#ifndef F_CPU
    #warning "H F_CPU den exei oristei 8a parei thn timh 8000000"
    #define F_CPU 8000000UL  //  Use unsigned long
#endif

/* Scheduler include files. */
#include "source/include/FreeRTOS.h"
#include "source/include/task.h"
#include "source/include/croutine.h"

void vLEDInit1(void);
void vLEDToggle1(void);
static void vLEDTask1(void* pvParameters);

void vLEDInit2(void);
void vLEDToggle2(void);
static void vLEDTask2(void* pvParameters);

int main(void){

    // Δημιουργία τον διεργασιών.
    xTaskCreate( vLEDTask1, ( signed char * ) "LED", configMINIMAL_STACK_SIZE, NULL, 1, NULL );
    xTaskCreate( vLEDTask2, ( signed char * ) "LED", configMINIMAL_STACK_SIZE, NULL, 1, NULL );



vTaskStartScheduler();


    while(1){
    	//hope we never get here
    	PORTC=0x00;
    	_delay_ms(250);
    	PORTC=0xff;
    	_delay_ms(100);
    };

    return 0;
}


static void vLEDTask1(void* pvParameters){

    const uint16_t blinkDelay = 250 ;

    vLEDInit1();


     while (1){

         vTaskDelay(blinkDelay);

		 vLEDToggle1();

         vTaskDelay(blinkDelay);

    }
}

static void vLEDTask2(void* pvParameters){

    const uint16_t blinkDelay = 500;

    vLEDInit2();


     while (1){

         vTaskDelay(blinkDelay);

		 vLEDToggle2();

         vTaskDelay(blinkDelay);

    }
}

void vLEDInit1(void){

    DDRC |= (1<<PC5);

}

void vLEDInit2(void){

    DDRC |= (1<<PC1);
}

void vLEDToggle1(void){

   PORTC ^= (1<<PC5);
}

void vLEDToggle2(void){

   PORTC ^= (1<<PC1);
}
